//
//  MineShareFriendController.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/11.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

class MineShareFriendController: UIViewController ,UITableViewDelegate,UITableViewDataSource{
    
    let CellId = "CellId"

    var tableView:UITableView = UITableView.init(frame: .zero, style: .plain)
    
    var headerView:MineShareHeaDerView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.createTableView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.setNavi()
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
}
extension MineShareFriendController{
    //MARK:设置导航栏选项
    func setNavi(){
        self.navigationItem.title = "邀请好友"
        self.navigationController?.navigationBar.barTintColor = .red
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.black]
        self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "", imagStr: "ic_back", fontSize: 14, target: self, action: #selector(leftBarButtonAction))
    }
    //MARK:leftBarButtonAction
    func leftBarButtonAction(){
        self.navigationController!.popViewController(animated: true)
    }
    //MARK:createTableView
    func createTableView(){
        self.tableView.tableHeaderView = self.headerView
        self.headerView?.backgroundColor = .red
        self.view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.register(MIneShareFriendCell.self, forCellReuseIdentifier: CellId)
        self.headerView = MineShareHeaDerView.init(frame: .zero)
        self.headerView?.frame = CGRect.init(x: 0, y: 64, width: k_Wide, height: 166 + (self.headerView?.noticeLabel.jqGetHeightWithstr("没成功邀请1位用户(被邀请用户需注册并绑定手机号),邀请用户即可获得10徽币的奖励，所获徽币可以参与平台活动所获徽币可以参与平台活动所获徽币可以参与平台活动", withfontSize: 14, withLineSpace: 0, withmaxWidth: k_Wide - 32))!)
        self.tableView.tableHeaderView = self.headerView
    }
    //MARK:HeaderViewDelegate
//    func returnHeightOfHeaderView(_ height: CGFloat) {
//        self.headerView?.frame = CGRect.init(x: 0, y: 0, width: k_Wide, height: height)
//        self.tableView.tableHeaderView = self.headerView
//        self.headerView?.backgroundColor = .red
//        self.view.addSubview(self.tableView)
//        self.tableView.snp.makeConstraints { (make) in
//            make.left.equalTo(0)
//            make.right.equalTo(0)
//            make.top.equalTo(0)
//            make.bottom.equalTo(0)
//        }
//        self.tableView.delegate = self
//        self.tableView.dataSource = self
//        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: CellId)
//    }
    //MARK:TableviewDelegate
    @objc(tableView:didSelectRowAtIndexPath:) func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("选中")
        self.headerView?.frame = CGRect.init(x: 0, y: 64, width: k_Wide, height: 500)
        self.headerView?.backgroundColor = .red
        self.tableView.reloadData()
    }
    @objc(numberOfSectionsInTableView:) func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    @objc(tableView:heightForRowAtIndexPath:) func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        switch indexPath.row {
        case 0:
            return 40
        default:
            return 64
        }
    }
    @objc(tableView:cellForRowAtIndexPath:) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
        switch indexPath.row {
        case 0:
            let cell = MIneShareFriendCell.init(style: .default, reuseIdentifier: CellId, cellStyle: .YaoQingStyle)
            (cell ).leftLabel.text = "邀请好友10位好友成功"
            return cell
        default:
            let cell = MIneShareFriendCell.init(style: .default, reuseIdentifier: CellId, cellStyle: .NormalStyle)
            (cell ).rightLabel.text = "手机号:无"
            (cell ).leftLabel.text = "昵称:快乐的人"
            (cell ).leftLabel_Dow.text = "时间:2016-10-29 00:00:00"
            return cell
        }
    }
}
